package com.maxmlr.music.admin.controller;

import com.maxmlr.music.admin.entity.User;
import com.maxmlr.music.admin.param.UserParam;
import com.maxmlr.music.admin.service.UserService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.Serializable;

/**
 * @author max
 * @version 1.0
 * @ClassName AdminUserController
 * @Description  页面跳转控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-14
 */
@Slf4j
@Controller
@Api(value = "/admin/user", tags = "User 页面跳转控制器")
@RequestMapping("/admin/user")
public class AdmUserController {

    @Autowired
    public UserService service;

    /**
     *  功能列表主页
     *
     * @return string
     */
    @GetMapping
    @RequiresPermissions("admin:user:user")
    public String user() {
        return "admin/user/user";
    }

    /**
     *  添加页面
     *
     * @return string
     */
    @GetMapping("/add")
    @RequiresPermissions("admin:user:add")
    public String add(){
        return "admin/user/add";
    }

    /**
     *  编辑页面
     *
     * @return string
     */
    @GetMapping("/edit/{id}")
    @RequiresPermissions("admin:user:edit")
    public String edit(@PathVariable("id") Serializable id, Model model) {
        UserParam param = service.getUserParamById(id);
        model.addAttribute("user", param);
        return "admin/user/edit";
    }

    /**
     *  密码重置页面
     *
     * @return string
     */
    @GetMapping("/reset-pwd/{id}")
    @RequiresPermissions("admin:user:resetPwd")
    public String resetPwd(@PathVariable("id") Serializable id, Model model) {
        UserParam param = service.getUserParamById(id);
        model.addAttribute("user", param);
        return "admin/user/reset_pwd";
    }


    /**
     *  密码重置页面
     *
     * @return string
     */
    @GetMapping("/personal")
    @RequiresPermissions("admin:user:personal")
    public String personal(Model model) {
        User user = service.getAdminUser();
        model.addAttribute("user", user);
        return "admin/user/personal";
    }

}
